package com.pybox.api;

import com.pybox.entity.TServerLogs;
import com.pybox.service.TCanbinetEventLogsService;
import com.pybox.dto.TCanbinetEventLogsDto;

import com.pybox.dto.Result;

import com.pybox.service.TServerLogService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;

/**
 * 描述：TCanbinetEventLogs Api
 *
 * @author wuyingkai
 * @date 2018-09-15
 */

@Slf4j
@RequestMapping("/TCanbinetServerEventLogsApi")
@Api(tags = "TCanbinetServerEventLogsApi管理接口")
@RestController
public class TCanbinetServerEventLogsApi {

    @Autowired
    private TCanbinetEventLogsService service;

    @Autowired
    private TServerLogService tServerLogService;

    /**
     * @return com.pybox.dto.Result<org.springframework.data.domain.Page < com.pybox.dto.TCanbinetEventLogsDto>>
     * @des 分页查询服务端日志操作
     * @className page
     * @param: startTime
     * @param: endTime
     * @param: operate
     * @param: pageNo
     * @param: pageSize
     * @anthor LeiYang
     * @date 2019/6/27
     */
    @ApiOperation(value = "分页查询TCanbinetServerEventLogsApi(服务端操作日志查询)")
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "startTime", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "endTime", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "operate", value = "operate", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "userName", value = "userName", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pageNo", value = "pageNo", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", dataType = "int", paramType = "query")
    })
    public Result<Page<TServerLogs>> pageQuery(
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime,
            @RequestParam(required = false) String operate,
            @RequestParam(required = false) String userName,
            @RequestParam Integer pageNo,
            @RequestParam Integer pageSize) {

        Map<String, String> params = new HashMap<>();

        params.put("startTime", startTime);
        params.put("endTime", endTime);
        params.put("operate", operate);
        params.put("userName", userName);
        return Result.ok(tServerLogService.pageQuery(pageNo, pageSize, params));
    }

    /**
     * @return com.pybox.dto.Result<org.springframework.data.domain.Page < com.pybox.dto.TCanbinetEventLogsDto>>
     * @des 服务端操作日志导出为excel
     * @className page
     * @param: startTime
     * @param: endTime
     * @param: operate
     * @anthor LeiYang
     * @date 2019/6/27
     */
    @ApiOperation(value = "根据条件导出TCanbinetServerEventLogsApi(服务端操作日志excel导出)")
    @RequestMapping(value = "/exportExcel", method = RequestMethod.GET)
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "startTime", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "endTime", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "operate", value = "operate", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "userName", value = "userName", dataType = "string", paramType = "query")
    })
    public void exportExcel(
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime,
            @RequestParam(required = false) String operate,
            @RequestParam(required = false) String userName,
            HttpServletResponse response
    ) throws IOException {

        Map<String, String> params = new HashMap<>();

        params.put("startTime", startTime);
        params.put("endTime", endTime);
        params.put("operate", operate);
        params.put("userName", userName);
        tServerLogService.exportExcel(params, response);

    }
}